home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Graphics / SPD / Sources / libdmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-27  |  6.7 KB  |  262 lines  |  [TEXT/R*ch]

  1. /*
  2.  * lib.c - a library of deferred object output routines.
  3.  *
  4.  * Author:  Eric Haines, 3D/Eye, Inc.
  5.  *
  6.  */
  7.  
  8. /*-----------------------------------------------------------------*/
  9. /* include section */
  10. /*-----------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <math.h>
  15. #include <string.h>
  16.  
  17. #include "lib.h"
  18. #include "drv.h"
  19.  
  20.  
  21. /*-----------------------------------------------------------------*/
  22. /* defines/constants section */
  23. /*-----------------------------------------------------------------*/
  24.  
  25.  
  26. /*-----------------------------------------------------------------*/
  27. void
  28. dump_plg_file PARAMS((void))
  29. {
  30.     object_ptr temp_obj;
  31.     int i;
  32.     unsigned int fcnt, vcnt;
  33.  
  34.     fcnt = 0;
  35.     vcnt = 0;
  36.     for (temp_obj = gPolygon_stack;
  37.      temp_obj != NULL;
  38.      temp_obj = temp_obj->next_object) {
  39.     fcnt++;
  40.     vcnt += temp_obj->object_data.polygon.tot_vert;
  41.     }
  42.  
  43.     fprintf(gOutfile, "objx %d %d\n", vcnt, fcnt);
  44.  
  45.     /* Dump all vertices */
  46.     for (temp_obj = gPolygon_stack;
  47.      temp_obj != NULL;
  48.      temp_obj = temp_obj->next_object) {
  49.  
  50.     PLATFORM_MULTITASK();
  51.     for (i=0;i<temp_obj->object_data.polygon.tot_vert;i++) {
  52.         fprintf(gOutfile, "%g %g %g\n",
  53.            temp_obj->object_data.polygon.vert[i][X],
  54.            temp_obj->object_data.polygon.vert[i][Y],
  55.            temp_obj->object_data.polygon.vert[i][Z]);
  56.     }
  57.     }
  58.  
  59.     /* Dump all faces */
  60.     vcnt = 0;
  61.     for (temp_obj = gPolygon_stack;
  62.      temp_obj != NULL;
  63.      temp_obj = temp_obj->next_object) {
  64.  
  65.     PLATFORM_MULTITASK();
  66.     fprintf(gOutfile, "0x11ff %d ", temp_obj->object_data.polygon.tot_vert);
  67.     for (i=0;i<temp_obj->object_data.polygon.tot_vert;i++)
  68.         fprintf(gOutfile, "%d ", vcnt + i);
  69.     fprintf(gOutfile, "\n");
  70.     vcnt += i;
  71.     }
  72. }
  73.  
  74. /*-----------------------------------------------------------------*/
  75. void
  76. dump_obj_file PARAMS((void))
  77. {
  78.     object_ptr temp_obj;
  79.     int i;
  80.     unsigned int fcnt, vcnt;
  81.  
  82.     fcnt = 0;
  83.     vcnt = 0;
  84.     for (temp_obj = gPolygon_stack;
  85.      temp_obj != NULL;
  86.      temp_obj = temp_obj->next_object) {
  87.     fcnt++;
  88.     vcnt += temp_obj->object_data.polygon.tot_vert;
  89.     }
  90.  
  91.     /* Dump all vertices */
  92.     for (temp_obj = gPolygon_stack;
  93.      temp_obj != NULL;
  94.      temp_obj = temp_obj->next_object) {
  95.  
  96.     PLATFORM_MULTITASK();
  97.     for (i=0;i<temp_obj->object_data.polygon.tot_vert;i++) {
  98.         fprintf(gOutfile, "v %g %g %g\n",
  99.            temp_obj->object_data.polygon.vert[i][X],
  100.            temp_obj->object_data.polygon.vert[i][Y],
  101.            temp_obj->object_data.polygon.vert[i][Z]);
  102.     }
  103.     }
  104.  
  105.     /* Dump all faces */
  106.     vcnt = 0;
  107.     for (temp_obj = gPolygon_stack;
  108.      temp_obj != NULL;
  109.      temp_obj = temp_obj->next_object) {
  110.  
  111.     PLATFORM_MULTITASK();
  112.     fprintf(gOutfile, "f ", temp_obj->object_data.polygon.tot_vert);
  113.     for (i=0;i<temp_obj->object_data.polygon.tot_vert;i++) {
  114.         fprintf(gOutfile, "%d", vcnt + i + 1);
  115.         if (i < temp_obj->object_data.polygon.tot_vert - 1)
  116.            fprintf(gOutfile, " ");
  117.         }
  118.     fprintf(gOutfile, "\n");
  119.     vcnt += i;
  120.     }
  121. }
  122.  
  123. /*-----------------------------------------------------------------*/
  124. void
  125. dump_all_objects()
  126. {
  127.     object_ptr temp_obj;
  128.  
  129.     if (gRT_out_format == OUTPUT_RTRACE)
  130.     fprintf(gOutfile, "Objects\n");
  131.  
  132.     /* Step through all objects dumping them as we go. */
  133.     for (temp_obj = gLib_objects;
  134.      temp_obj != NULL;
  135.      temp_obj = temp_obj->next_object) {
  136.  
  137.     PLATFORM_MULTITASK();
  138.     lookup_surface_stats(temp_obj->surf_index,
  139.         &gTexture_count, &gTexture_ior);
  140.     switch (temp_obj->object_type) {
  141.         case BOX_OBJ:
  142.         lib_output_box(temp_obj->object_data.box.point1,
  143.                    temp_obj->object_data.box.point2);
  144.         break;
  145.         case CONE_OBJ:
  146.         lib_output_cylcone(temp_obj->object_data.cone.base_pt,
  147.                    temp_obj->object_data.cone.apex_pt,
  148.                    temp_obj->curve_format);
  149.         break;
  150.         case DISC_OBJ:
  151.         lib_output_disc(temp_obj->object_data.disc.center,
  152.                 temp_obj->object_data.disc.normal,
  153.                 temp_obj->object_data.disc.iradius,
  154.                 temp_obj->object_data.disc.oradius,
  155.                 temp_obj->curve_format);
  156.         break;
  157.         case HEIGHT_OBJ:
  158.         lib_output_height(temp_obj->object_data.height.filename,
  159.                   temp_obj->object_data.height.data,
  160.                   temp_obj->object_data.height.height,
  161.                   temp_obj->object_data.height.width,
  162.                   temp_obj->object_data.height.x0,
  163.                   temp_obj->object_data.height.x1,
  164.                   temp_obj->object_data.height.y0,
  165.                   temp_obj->object_data.height.y1,
  166.                   temp_obj->object_data.height.z0,
  167.                   temp_obj->object_data.height.z1);
  168.         break;
  169.         case POLYGON_OBJ:
  170.         lib_output_polygon(temp_obj->object_data.polygon.tot_vert,
  171.                    temp_obj->object_data.polygon.vert);
  172.         break;
  173.         case POLYPATCH_OBJ:
  174.         lib_output_polypatch(temp_obj->object_data.polypatch.tot_vert,
  175.                      temp_obj->object_data.polypatch.vert,
  176.                      temp_obj->object_data.polypatch.norm);
  177.         break;
  178.         case SPHERE_OBJ:
  179.         lib_output_sphere(temp_obj->object_data.sphere.center_pt,
  180.                   temp_obj->curve_format);
  181.         break;
  182.         case SUPERQ_OBJ:
  183.         lib_output_sq_sphere(temp_obj->object_data.superq.center_pt,
  184.                      temp_obj->object_data.superq.a1,
  185.                      temp_obj->object_data.superq.a2,
  186.                      temp_obj->object_data.superq.a3,
  187.                      temp_obj->object_data.superq.n,
  188.                      temp_obj->object_data.superq.e);
  189.         break;
  190.         case TORUS_OBJ:
  191.         lib_output_torus(temp_obj->object_data.torus.center,
  192.                  temp_obj->object_data.torus.normal,
  193.                  temp_obj->object_data.torus.iradius,
  194.                  temp_obj->object_data.torus.oradius,
  195.                  temp_obj->curve_format);
  196.         break;
  197.         default:
  198.         fprintf(gOutfile, "Bad object type: %d\n",
  199.               temp_obj->object_type);
  200.         exit(1);
  201.     }
  202.     }
  203.  
  204.     if (gRT_out_format == OUTPUT_RTRACE)
  205.     fprintf(gOutfile, "\n");
  206. }
  207.  
  208. /*-----------------------------------------------------------------*/
  209. void
  210. dump_reorder_surfaces()
  211. {
  212.     surface_ptr temp_ptr, head_ptr = NULL;
  213.  
  214.     while (gLib_surfaces != NULL) {
  215.     temp_ptr = gLib_surfaces;
  216.     gLib_surfaces = gLib_surfaces->next;
  217.     temp_ptr->next = head_ptr;
  218.     head_ptr = temp_ptr;
  219.     }
  220.  
  221.     gLib_surfaces = head_ptr;
  222. }
  223.  
  224. /*-----------------------------------------------------------------*/
  225. void
  226. dump_all_lights()
  227. {
  228.     light_ptr temp_ptr = gLib_lights;
  229.  
  230.     if (gRT_out_format == OUTPUT_RTRACE)
  231.     fprintf(gOutfile, "Lights\n");
  232.  
  233.     while (temp_ptr != NULL) {
  234.     lib_output_light(temp_ptr->center_pt);
  235.     temp_ptr = temp_ptr->next;
  236.     }
  237.  
  238.     if (gRT_out_format == OUTPUT_RTRACE)
  239.     fprintf(gOutfile, "\n");
  240. }
  241.  
  242. /*-----------------------------------------------------------------*/
  243. void
  244. dump_all_surfaces()
  245. {
  246.     surface_ptr temp_ptr = gLib_surfaces;
  247.  
  248.     if (gRT_out_format == OUTPUT_RTRACE)
  249.     fprintf(gOutfile, "Surfaces\n");
  250.  
  251.     while (temp_ptr != NULL) {
  252.     lib_output_color(temp_ptr->surf_name, temp_ptr->color, temp_ptr->ka,
  253.                   temp_ptr->kd, temp_ptr->ks, temp_ptr->shine,
  254.                   temp_ptr->ang, temp_ptr->kt, temp_ptr->ior);
  255.     temp_ptr = temp_ptr->next;
  256.     }
  257.  
  258.     if (gRT_out_format == OUTPUT_RTRACE)
  259.     fprintf(gOutfile, "\n");
  260. }
  261.  
  262.